package tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * TCP服务端
 *
 * @author : itheima
 * @date : 2021/8/30 5:44 PM
 **/
public class TcpServer {
    public static void main(String[] args) throws IOException {
        // 步骤1：创建Socket对象
        ServerSocket ss = new ServerSocket(10000);

        // 步骤2：等待客户端连接(监听客户端连接)
        System.out.println(111);
        Socket accept = ss.accept();
        System.out.println(222);

        // 步骤3：获得输入流对象
        InputStream is = accept.getInputStream();
        int b;
        while ((b = is.read()) != -1) {
            System.out.print((char) b);
        }


        // 步骤3：数组写法（是不是发现和IO字节流很像？）
        //byte[] bytes = new byte[1024];
        //while (is.read(bytes) == 0) {
        //    System.out.println(new String(bytes));
        //}


        System.out.println("看看我执行了吗?");

        // 步骤4：释放资源
        is.close();
        ss.close();
    }
}
